import axios from 'axios';
import IUser from '../interfaces/IUser';
import { IMenu } from '../interfaces/IMenu';

export type ParentCodeEnum = 'CONTROL_CENTER' | 'STORE_MANAGER';

/**
 * 获取当前登录用户信息
 */
export const fetchUserInfo = (): Promise<{ data: IUser, errorCode: number }> => {
  return axios.get(`/users/_current`).then(res => res.data);
}

/**
 * 获取当前登录用户拥有权限的菜单
 * @param parentCode
 */
export const fetchUserMenu = (parentCode: ParentCodeEnum): Promise<{ data: IMenu[], errorCode: number }> => {
  return axios.get(`/users/menus?parentCode=${parentCode}`).then(res => res.data);
}
